<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%contract_file}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%contract}}`
 */
class m230206_070739_create_contract_file_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%contract_file}}', [
            'id' => $this->primaryKey(),
            'title' => $this->string(512)->notNull(),
            'filename' => $this->string()->notNull(),
            'id_contract' => $this->integer()->notNull(),
        ]);

        // creates index for column `id_contract`
        $this->createIndex(
            '{{%idx-contract_file-id_contract}}',
            '{{%contract_file}}',
            'id_contract'
        );

        // add foreign key for table `{{%contract}}`
        $this->addForeignKey(
            '{{%fk-contract_file-id_contract}}',
            '{{%contract_file}}',
            'id_contract',
            '{{%contract}}',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%contract}}`
        $this->dropForeignKey(
            '{{%fk-contract_file-id_contract}}',
            '{{%contract_file}}'
        );

        // drops index for column `id_contract`
        $this->dropIndex(
            '{{%idx-contract_file-id_contract}}',
            '{{%contract_file}}'
        );

        $this->dropTable('{{%contract_file}}');
    }
}
